/***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
**Table 3: CARs event study around BTD announcements:

For detailed information on the variables used in these analyses, see the pdf document "Read Me - Firm-level Tests"
***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************/

use pseudo_btd_CARs,replace

	***************************************************************************
	**Table 3: First Column Replication
	***************************************************************************
	reghdfe car1w btd_firm btd_rival  ,abs(permno trade_date) vce(cluster permno)
	outreg2 using Table3.xls, append dec(3) tstat ctitle(full sample) keep(btd_firm btd_rival ) addtext(Firm FE,  Yes,Event-day FE, Yes)
	***************************************************************************
	*Table 3: Second Column Replication SMST and SM rivals in the full sample
	***************************************************************************
	reghdfe car1w btd_firm smst_rival sm_rival  ,abs(permno trade_date) vce(cluster permno)
	outreg2 using Table3.xls, append dec(3) tstat ctitle(full sample) keep(btd_firm smst_rival sm_rival) addtext(Firm FE,  Yes,Event-day FE, Yes, Cluster SE by , Firm)
	***************************************************************************
	*Table 3: Third Column Replication SMST rivals in the rivals only subsample
	***************************************************************************	
	reghdfe car1w smst_rival if btd_rival==1 & previous_btd_firm!=1,abs( trade_date) vce(cluster permno)
	outreg2 using Table3.xls, append dec(3) tstat ctitle(Rivals Sample) keep(smst_rival) addtext(Firm FE,  No,Event-day FE, Yes, Cluster SE by , Firm)

/***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
**Table 4: BTD Shocks and Firm level innovation: R&D exp and Patents:

For detailed information on the variables used in these analyses, see the pdf document "Read Me - Firm-level Tests"

***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************/

use pseudo_btd_firm_innovation,replace

foreach dep_var in patdummy  patnumc xrdw_atw{
	***************************************************************************
	**Table 4: Columns 1, 4, and 7
	***************************************************************************
	reghdfe `dep_var' btd_firmq4 btd_rivalq4  ,abs(realid fqdate) vce(cluster realid)
	outreg2 using Table4.xls, append dec(3) tstat ctitle(full sample) keep(btd_firmq4 btd_rivalq4 ) addtext(Firm FE,  Yes,Calendar Qtr FE, Yes)
	***************************************************************************
	*Table 4: Columns 2, 5 and 8
	***************************************************************************
	reghdfe `dep_var' btd_firmq4 smst_rivalq4 sm_rivalq4  ,abs(realid fqdate) vce(cluster realid)
	outreg2 using Table4.xls, append dec(3) tstat ctitle(full sample) keep(btd_firmq4 smst_rivalq4 sm_rivalq4) addtext(Firm FE,  Yes,Calendar Qtr FE, Yes, Cluster SE by , Firm)
	***************************************************************************
	*Table 4: Columns 3, 6 and 9
	***************************************************************************	
	reghdfe `dep_var' smst_rivalq4 if btd_rivalq4==1 & btd_firmq4!=1,abs(realid fqdate) vce(cluster realid)
	outreg2 using Table4.xls, append dec(3) tstat ctitle(Rivals Sample) keep(smst_rivalq4) addtext(Firm FE,  Yes,Calendar Qtr FE, Yes, Cluster SE by , Firm)
}

/***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
**Table 8 Panel B: Rival initiations following BTD shocks:

For detailed information on the variables used in these analyses, see the pdf document "Read Me - Firm-level Tests"

***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************/

use pseudo_btd_rival_init,replace


/*************
regressions for columns 1-3
***********/
	
***identify the dependent variable: initiation (column 1), lowcomp_initiation (column 2) and hicomp_initiation (column 3)
	foreach dep_var in initiation lowcomp_initiation hicomp_initiation{
		
			 reghdfe `dep_var' hicomp_hiexp_rival hiexp_rival hicomp_rival     ,abs(realid  fqdate) vce(cluster realid)
			  outreg2 using Table8.xls, append dec(3) tstat ctitle(full_`dep_var') keep(hicomp_hiexp_rival hiexp_rival hicomp_rival)
	}

/*************
regressions for columns 3-6
***********/
	
***identify the dependent variable: initiation (column 4), lowcomp_initiation (column 5) and hicomp_initiation (column 6)
	foreach dep_var in initiation lowcomp_initiation hicomp_initiation{
		
			 reghdfe `dep_var'  hicomp_rival if hiexp_rival==1,abs(realid  fqdate) vce(cluster realid)
			  outreg2 using Table8.xls, append dec(3) tstat ctitle(hiexp_`dep_var') keep(hicomp_rival)
	}

/***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************
**Table 9 : BTD Rivals' Financial outcomes

For detailed information on the variables used in these analyses, see the pdf document "Read Me - Firm-level Tests"

***************************************************************************
***************************************************************************
***************************************************************************
***************************************************************************/

use pseudo_btd_rival_fin,replace

/**********************************************************************************
	
***Panel A: APP and BTD rivals full sample
	
**********************************************************************************/
		
	***dependet variable is: acquisition cashw_atw sgaw_revw leveragew
	foreach dep_var in acquisition cashw_atw sgaw_revw leveragew {

		***First 4 columns of Panel A:

		reghdfe `dep_var'  btd_rivalq4,abs(realid  fqdate) vce(cluster realid)
		outreg2 using Table9.xls, append dec(3) tstat ctitle(full_`dep_var') keep(btd_rivalq4)
		
		***last 4 columns of Panel A:

		reghdfe `dep_var'  btd_rivalq4 approved_rivalq4,abs(realid  fqdate) vce(cluster realid)
		outreg2 using Table9.xls, append dec(3) tstat ctitle(full_`dep_var') keep(btd_rivalq4 approved_rivalq4)
		
	}
	
/**********************************************************************************
	
***Panel B: APP rivals in rivals only sample
	
**********************************************************************************/
	
***identify whether a rival is shocked in last 4 (first four columns) or 8 quarters (last 4 columns):
foreach shockq in 4 8{	
	
	***dependet variable is: acquisition cashw_atw sgaw_revw leveragew
	foreach dep_var in acquisition cashw_atw sgaw_revw leveragew {

		reghdfe `dep_var'  approved_rivalq`shockq' if btd_rivalq`shockq'==1,abs(realid  fqdate) vce(cluster realid)
		outreg2 using Table9.xls, append dec(3) tstat ctitle(sample`shockq'_`dep_var') keep(approved_rivalq`shockq')
				
	}

}